package endurance.controller;

import endurance.listener.MessageEntity;
import endurance.observer.listener.ListenerObserver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @Author: sunlin
 * @Date: 2024-05-04 12:56
 * @Version: 1.0
 * @Description:
 */
@Slf4j
@RestController
public class UserController {

    @Autowired
    private ListenerObserver listenerObserver;

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;


    @RequestMapping("/notify")
    public String notify1() {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("phone", "18852452660");
        hashMap.put("sms", "7458241452@qq.com");
        listenerObserver.notifyObservers(hashMap);
        return "发送成功";
    }

    @RequestMapping("/notify2")
    public String notify2() {

        MessageEntity messageEntity = new
                MessageEntity(this, "458241452@qq.com", "18852452660");
        applicationEventPublisher.publishEvent(messageEntity);
        return "发送成功";
    }


}
